from pyecharts import options as opts
from pyecharts.charts import Map
from pyecharts.faker import Faker
import os


class Mapping:
    def __init__(self):
        if not os.path.exists('./city_map'):
            os.mkdir('./city_map')

    def china_map(self, area, confirmed, update_time):
        pieces = [
            {"max": 99999999, "min": 10000, "label": '>10000', "color": '#8B0000'},
            {"max": 9999, "min": 1000, "label": '1000-9999', "color": '#CD3333'},
            {"max": 999, "min": 100, "label": '100-999', "color": '#CD5C5C'},
            {"max": 99, "min": 10, "label": '10-99', "color": '#F5A9A9'},
            {"max": 9, "min": 1, "label": '1-9', "color": '#FFEBCD'},
            {"max": 0, "min": 0, "label": '0', "color": '#FFFFF'},
        ]
        c = (
            Map(init_opts=opts.InitOpts(width='800px', height='600px'))
            .add("累计确诊人数", [list(z) for z in zip(area, confirmed)], "china")
            .set_global_opts(
                title_opts=opts.TitleOpts(title="国内疫情地图分布",
                                          subtitle="截止{}地区疫情分布情况".format(update_time)),
                visualmap_opts=opts.VisualMapOpts(max_=200, is_piecewise=True, pieces=pieces)
            )
            .render("./国内疫情地图.html")
        )

    def province_map(self, city, confirmed, province, update_time):
        pieces = [
            {"max": 99999999, "min": 10000, "label": '>10000', "color": '#8B0000'},
            {"max": 9999, "min": 1000, "label": '1000-9999', "color": '#CD3333'},
            {"max": 999, "min": 100, "label": '100-999', "color": '#CD5C5C'},
            {"max": 99, "min": 10, "label": '10-99', "color": '#F5A9A9'},
            {"max": 9, "min": 1, "label": '1-9', "color": '#FFEBCD'},
            {"max": 0, "min": 0, "label": '0', "color": '#FFFFF'},
        ]
        c = (
            Map(init_opts=opts.InitOpts(width='800px', height='600px'))
                .add("累计确诊人数", [list(z) for z in zip(city, confirmed)], province)
                .set_global_opts(
                title_opts=opts.TitleOpts(title="{}地区疫情地图分布".format(province),
                                          subtitle="截止{}{}地区疫情分布情况".format(update_time, province)),
                visualmap_opts=opts.VisualMapOpts(max_=200, is_piecewise=True, pieces=pieces)
            )
                .render("./city_map/{}地区疫情地图.html".format(province))
        )

    def world_map(self, country, confirmeds, update_time):
        pieces = [
            {"max": 9999999, "min": 500000, "label": '500000-9999999', "color": '#000000'},
            {"max": 499999, "min": 100000, "label": '100000-499999', "color": '#8B0000'},
            {"max": 99999, "min": 10000, "label": '10000-99999', "color": '#8B3626'},
            {"max": 9999, "min": 1000, "label": '1000-9999', "color": '#CD3333'},
            {"max": 999, "min": 100, "label": '100-999', "color": '#CD5C5C'},
            {"max": 99, "min": 10, "label": '10-99', "color": '#F5A9A9'},
            {"max": 9, "min": 1, "label": '1-9', "color": '#FFEBCD'},
            {"max": 0, "min": 0, "label": '0', "color": '#FFFFE0'},
        ]
        c = (
            Map(init_opts=opts.InitOpts(width='800px', height='600px'))
                .add("累计确诊人数", [list(z) for z in zip(country, confirmeds)], "world")
                .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
                .set_global_opts(
                title_opts=opts.TitleOpts(title="世界疫情地图", subtitle="截止{}世界疫情分布情况".format(update_time)),
                visualmap_opts=opts.VisualMapOpts(max_=300, is_piecewise=True, pieces=pieces),
            )
                .render("./世界疫情地图.html")
        )


if __name__ == '__main__':
    map = Mapping()
